package vue.consultation;

import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.TitledBorder;

import controler.Poi;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class ConsultPoi extends JPanel {

	private Poi currentPoi;
	private int count = 0;
	private JPanel contentPane;
	private JPanel panelBase;
	private JPanel panel_1;
	private JPanel panel_2;
	private JPanel panel_3;
	private JPanel panel_4;
	private JPanel panel_5;
	private JPanel panel_6;
	private JPanel panel_7;
	//private JTextField imageArea;
	
	private JLabel lblLibPoi;
	private JLabel lblImage;
	private JLabel lblDescription;
	private JLabel lblLieuPoi;
	private JLabel lblPosX;
	private JLabel lblPosY;
	
	private ImageIcon TEST;
	
	private JButton bPrecedent;
	private JButton bSuivant;
	
	public ConsultPoi(JPanel contentPane) {
		
		this.contentPane = contentPane;
		
		
	}
	public void initComponents(){
		if(panelBase instanceof JPanel){
		panelBase.removeAll();
		}
		setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
		
		panelBase = new JPanel();
		contentPane.add(panelBase);
		panelBase.setLayout(new BoxLayout(panelBase, BoxLayout.Y_AXIS));
		
	    panel_1 = new JPanel();
		panelBase.add(panel_1);
		panel_1.setLayout(new BoxLayout(panel_1, BoxLayout.X_AXIS));
		
		
		panel_3 = new JPanel();
		panel_3.setBorder(new TitledBorder(null, "Image POI", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel_1.add(panel_3);
		lblImage = new JLabel("");
		panel_3.add(lblImage);
		
		panel_4 = new JPanel();
		panel_1.add(panel_4);
		panel_4.setLayout(new BoxLayout(panel_4, BoxLayout.Y_AXIS));
		
		panel_5 = new JPanel();
		panel_4.add(panel_5);
		panel_5.setBorder(new TitledBorder(null, "Libelle POI", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		this.lblLibPoi = new JLabel("libelle");
		panel_5.add(lblLibPoi);
		
		panel_6 = new JPanel();
		panel_4.add(panel_6);
		panel_6.setBorder(new TitledBorder(null, "Description POI", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		lblDescription = new JLabel("Description");
		panel_6.add(lblDescription);
		
		panel_7 = new JPanel();
		panel_4.add(panel_7);
		panel_7.setBorder(new TitledBorder(null, "Detail du POI", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		lblLieuPoi = new JLabel("Lieu");
		panel_7.add(lblLieuPoi);
		
		lblPosX = new JLabel("posX");
		panel_7.add(lblPosX);
		
		lblPosY = new JLabel("posY");
		panel_7.add(lblPosY);
		
		panel_2 = new JPanel();
		panelBase.add(panel_2);
		
		bPrecedent = new JButton("Pr\u00E9c\u00E9dent");
		bPrecedent.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				count--;
				initComponents();
			}
		});
		panel_2.add(bPrecedent);
		
		bSuivant = new JButton("Suivant");
		bSuivant.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				count++;
				initComponents();
				
			}
		});
		panel_2.add(bSuivant);
		initPoi();
	}
	
	public void initPoi() {
		
		if (!(panelBase instanceof JPanel)){
			initComponents();
	    }
		
		controler.consultation.ConsultPoi poi = new controler.consultation.ConsultPoi();
		currentPoi = poi.selectPoi(count);
		if (currentPoi == null ){
			count = 0;
			initPoi();
		}
		TEST = new ImageIcon(currentPoi.getImage());
		lblLibPoi.setText(currentPoi.getLibelle());
		lblImage.setIcon(TEST);
		lblDescription.setText(currentPoi.getDescription());
		lblLieuPoi.setText(currentPoi.getLieu().getLibelle() + "   ");
		lblPosX.setText(Integer.toString(currentPoi.getPosX()));
		lblPosY.setText(Integer.toString(currentPoi.getPosY()));
		
	}

}
